import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
@Setter
public class User {
    private String name;
    private Integer age;
    private String gender;

    public User() {

    }

    public User(String name, Integer age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    @Override
    public String toString() {
        return name + age + gender;
    }

    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("张三", 50, "男"));
        users.add(new User("张四", 89, "女"));
        users.add(new User("张五", 34, "男"));
        users.add(new User("张六", 23, "女"));

        System.out.println(users.stream().sorted(Comparator.comparing(User::getAge).reversed()).collect(Collectors.toList()));
        users.stream().
                filter(user -> user.getAge() >= 50).
                forEach(user -> {
                    System.out.println(user);
                });
        System.out.println(users.stream().filter(user -> user.getGender().equals("男")).count());
        System.out.println(users.stream().filter(user -> user.getGender().equals("女")).count());
        users.stream().filter(user -> user.getGender().equals("男")).forEach(user -> {
            System.out.println(user);
        });
        users.stream().filter(user -> user.getGender().equals("女")).forEach(user -> {
            System.out.println(user);
        });
    }

}
